package com.jwds.digital.bios.business.api.controller.dispatch;

import cn.hutool.json.JSONUtil;
import com.jwds.digital.bios.business.core.constants.DispatchConstant;
import com.jwds.digital.bios.business.core.infrastructure.dto.dispatch.DispatchFeedReqDTO;
import com.jwds.digital.bios.business.core.infrastructure.dto.dispatch.DispatchInternalTransportReqDTO;
import com.jwds.digital.bios.business.core.infrastructure.dto.dispatch.DispatchParameterReqDTO;
import com.jwds.digital.bios.business.core.infrastructure.entity.dispatch.DispatchFeed;
import com.jwds.digital.bios.business.core.infrastructure.vo.dispatch.DispatchFeedRespVO;
import com.jwds.digital.bios.business.core.infrastructure.vo.dispatch.DispatchInternalTransportRespVO;
import com.jwds.digital.bios.business.core.infrastructure.vo.feign.DispatchParameterRespVo;
import com.jwds.digital.bios.business.service.service.dispatch.IDispatchFeedService;
import com.jwds.tdc.framework.application.lib.BaseResponse;
import com.jwds.tdc.framework.application.lib.page.PageRequest;
import com.jwds.tdc.framework.application.lib.page.PageResponse;
import com.jwds.tdc.framework.cache.service.CacheService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jodd.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

import static cn.hutool.http.ContentType.JSON;

/**
 * 供料调度 前端控制器
 *
 * @author 林柏云
 * @date 2024-10-24
 */
@Slf4j
@Api(tags = "供料调度")
@RestController
@RequestMapping("/dispatch/feed")
public class DispatchFeedController {

  @Resource
  private IDispatchFeedService service;

  @Autowired
  private CacheService cacheService;

  @GetMapping("/{id}")
  @ApiOperation(value = "根据id查询")
  public BaseResponse<DispatchFeedRespVO> queryById(@PathVariable("id") Long id) {
    DispatchFeedRespVO respVo = service.queryById(id);
    return BaseResponse.success(respVo);
  }

  @PostMapping("/list")
  @ApiOperation(value = "分页查询")
  public BaseResponse<PageResponse<DispatchFeedRespVO>> page(@RequestBody PageRequest<DispatchFeedReqDTO> pageRequest) {
    PageResponse<DispatchFeedRespVO> respVoPage = service.page(pageRequest);
    return BaseResponse.success(respVoPage);
  }

  @PostMapping("/allBlastFurnace")
  @ApiOperation(value = "查询指定料仓数据数据")
  public BaseResponse<List<DispatchFeedRespVO>> list(String binName) {
    List<DispatchFeedRespVO> respVoList = service.listBlastFurnace(binName);
    return BaseResponse.success(respVoList);
  }

  @PostMapping("/allblastFurnace")
  @ApiOperation(value = "查询高炉料仓数据数据")
  public BaseResponse<List<DispatchFeedRespVO>> listBlastFurnace(String binName) {
    List<DispatchFeedRespVO> respVoList = service.blastFurnace(binName);
    return BaseResponse.success(respVoList);
  }


  @DeleteMapping("/{id}")
  @ApiOperation(value = "删除对象")
  public BaseResponse<?> delete(@PathVariable("id") Long id) {
    service.delete(id);
    return BaseResponse.success();
  }

  @GetMapping("originPointion/{originPointion}")
  @ApiOperation(value = "起点下拉框")
  public BaseResponse<List<String>> StartingPoint(@PathVariable String originPointion) {
    List<String> list = service.StartingPoint(originPointion);
    return BaseResponse.success(list);
  }
  @GetMapping("originDevice/{originDevice}")
  @ApiOperation(value = "起点设备下拉框")
  public BaseResponse<List<String>> destDevice(@PathVariable String originDevice) {
    List<String> respVoList = service.destDevice(originDevice);
    return BaseResponse.success(respVoList);
  }

  @PostMapping("/OriginDevice")
  @ApiOperation(value = "流程下拉框")
  public BaseResponse<List<String>> originDevice(@RequestBody DispatchFeedReqDTO reqDTO) {
    List<String> respVoList = service.originDevice(reqDTO);
    return BaseResponse.success(respVoList);
  }
  @PostMapping("/Execute")
  @ApiOperation(value = "执行")
  public BaseResponse<DispatchFeedRespVO> Execute(@RequestBody DispatchFeedReqDTO reqDTO) {
    DispatchFeedRespVO feedRespVO = service.execute(reqDTO);
    return BaseResponse.success(feedRespVO);
  }


  @GetMapping("/BallGroupAdd")
  @ApiOperation(value = "球团供料加仓")
  public BaseResponse<List<DispatchParameterReqDTO>> dispatchBallGroup() {
    String string = cacheService.getString(DispatchConstant.REDIS_KEY + ":QTPLC");
    if (StringUtil.isEmpty(string)) {
      return BaseResponse.success();
    }
    List<DispatchParameterReqDTO> data = JSONUtil.toList(string, DispatchParameterReqDTO.class);
    return BaseResponse.success(data);
  }

  @GetMapping("/SinterFeed2Add")
  @ApiOperation(value = "2#烧结供料加仓")
  public BaseResponse<List<DispatchParameterReqDTO>> SinterFeed2Add() {
    String string = cacheService.getString(DispatchConstant.REDIS_KEY + ":SJ2PLC");
    if (StringUtil.isEmpty(string)) {
      return BaseResponse.success();
    }
    List<DispatchParameterReqDTO> data = JSONUtil.toList(string, DispatchParameterReqDTO.class);
    return BaseResponse.success(data);
  }

  @GetMapping("/SinterFeed3Add")
  @ApiOperation(value = "3#烧结供料加仓")
  public BaseResponse<List<DispatchParameterReqDTO>> SinterFeed3Add() {
    String string = cacheService.getString(DispatchConstant.REDIS_KEY + ":SJ3PLC");
    if (StringUtil.isEmpty(string)) {
      return BaseResponse.success();
    }
    List<DispatchParameterReqDTO> data = JSONUtil.toList(string, DispatchParameterReqDTO.class);
    return BaseResponse.success(data);
  }

  @GetMapping("/SinterFeed4Add")
  @ApiOperation(value = "4#烧结供料加仓")
  public BaseResponse<List<DispatchParameterReqDTO>> SinterFeed4Add() {
    String string = cacheService.getString(DispatchConstant.REDIS_KEY + ":SJ4PLC");
    if (StringUtil.isEmpty(string)) {
      return BaseResponse.success();
    }
    List<DispatchParameterReqDTO> data = JSONUtil.toList(string, DispatchParameterReqDTO.class);
    return BaseResponse.success(data);
  }

  @GetMapping("/BYSAdd")
  @ApiOperation(value = "BYS供料加仓")
  public BaseResponse<List<DispatchParameterReqDTO>> BYSAdd() {
    String string = cacheService.getString(DispatchConstant.REDIS_KEY + ":BYSC");
    if (StringUtil.isEmpty(string)) {
      return BaseResponse.success();
    }
    List<DispatchParameterReqDTO> data = JSONUtil.toList(string, DispatchParameterReqDTO.class);
    return BaseResponse.success(data);
  }

  @GetMapping("/SHSAdd")
  @ApiOperation(value = "SHS供料加仓")
  public BaseResponse<List<DispatchParameterReqDTO>> SHSAdd() {
    String string = cacheService.getString(DispatchConstant.REDIS_KEY + ":SHSC");
    if (StringUtil.isEmpty(string)) {
      return BaseResponse.success();
    }
    List<DispatchParameterReqDTO> data = JSONUtil.toList(string, DispatchParameterReqDTO.class);
    return BaseResponse.success(data);
  }
}
